﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Xml;

namespace SW.Core
{
    public class SectionHandler : IConfigurationSectionHandler
    {
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            Hashtable ht = new Hashtable();
            foreach (XmlNode node in section.ChildNodes)
            {
                if (node.Name == "Template")
                {
                    ht.Add("TemplatePath", node.Attributes["Path"].Value);
                }
                else if (node.Name == "Connection")
                {
                    ht.Add("DbType", node.Attributes["Type"].Value);
                    ht.Add("DbHost", node.Attributes["Host"].Value);
                    ht.Add("DbName", node.Attributes["Name"].Value);
                    ht.Add("DbUser", node.Attributes["User"].Value);
                    ht.Add("DbPassword", node.Attributes["Password"].Value);
                }
                else if (node.Name == "Security")
                {
                    ht.Add("SecurityKey", node.Attributes["Key"].Value);
                    ht.Add("SecurityIV", node.Attributes["IV"].Value);
                }
            }
            return ht;
        }
    }
}